package org.dfl.plugin.dialogs;

import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

import javax.swing.Timer;

import org.dfl.plugin.editor.model.DflDiagram;

/**
 * dialog to edit taverna processor's properties
 * @author Piotr Wlodarczyk
 *
 */
public abstract class TavernaProcesorPropertiesListener implements WindowListener, ActionListener{
	Timer t = null;
	Window w;
	DflDiagram diagram;
	
	public TavernaProcesorPropertiesListener(DflDiagram diagram) {
		super();
		this.diagram = diagram;
	}
	
	public void windowOpened(WindowEvent e) {
		if(diagram!=null){
			diagram.setEditable(false);
		}
		
		w = e.getWindow();
		t = new Timer(1000,this);
		t.start();
		tavernaProcesorPropertiesWindowOpened(e.getWindow());
	}
	public  void windowClosed(WindowEvent e) {
		if(t!=null) t.stop();
		tavernaProcesorPropertiesWindowClosed(e.getWindow());
		if(diagram!=null){
			diagram.setEditable(true);
		}
	}
	
	public abstract void tavernaProcesorPropertiesWindowOpened(Window window);
	public abstract void tavernaProcesorPropertiesWindowClosed(Window window);
	
	public void windowDeactivated(WindowEvent e) {
		if(t!=null) t.stop();
	}
	public void windowDeiconified(WindowEvent e) {
		if(t!=null) t.stop();
	}
	public void windowIconified(WindowEvent e) {
		if(t!=null) t.start();
	}
	public void windowActivated(WindowEvent e) {
		if(t!=null) t.start();
	}
	public void windowClosing(WindowEvent e) {
		if(t!=null) t.stop();
	}
	
	// action timer performed
	public void actionPerformed(ActionEvent e) {
		if(w!=null) w.repaint();
	}
}
